<template>
  <el-dialog :title="title" v-model="props.visible" width="30%">
    <component
      v-if="children"
      :is="children"
      ref="childrenComponent"
    ></component>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="noHandle">取 消</el-button>
        <el-button type="primary" @click="okHandle">确 定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref, VueElement } from "vue";

const props = defineProps({
  children: {
    type: VueElement,
    default: null,
  },
  visible: {
    type: Boolean,
    default: true,
  },
  title: {
    type: String,
    default: "这个是头部",
  },
  msg: {
    type: String,
    default: "这个是内容",
  },
  okButtonTxt: {
    type: String,
    default: "确定",
  },
  noButtonTxt: {
    type: String,
    default: "取消",
  },
  okButton: {
    type: Function,
    default: () => {},
  },
  noButton: {
    type: Function,
    default: () => {},
  },
});

const childrenComponent = ref();
const noHandle = () => {};
const okHandle = () => {
  props.okButton(childrenComponent.value);
};
</script>
